<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../../build/common/base.css" rel="stylesheet">
<script type="text/javascript" src="../../build/common/base.js"></script>
<script type="text/javascript" src="../../build/common/vueEdit.js"></script>
</head>
<body>
	<div id="ctrl">
		<div class="ibox-title">
			<a class="btn btn-primary fa-save" href="javascript:void(0)" v-on:click="saveData">保存</a>
			<a href="javascript:void(0)" class="btn btn-primary fa-reply" onclick="javascript:$.Dialog.close(window);">返回</a>
		</div>
		<div v-if="loaded">
			<ab-custom-form></ab-custom-form>
		</div>
	</div>
</body>
<script type="text/javascript">
	var vm = new Vue({
		el : "#ctrl",
		data : function() {
			return {
				loaded : false
			}
		},
		beforeCreate : function() {
		},
		methods : {
			saveData : function() {
				var errorMsg = Vue.formService.getValidateMsg(this.$children[0]);
				if (errorMsg) {
					$.Dialog.alert("表单校验不通过！" + errorMsg, 7);
					return;
				}
				// 业务校验
				 if (this.$children[0].custValid) {
			        if (this.$children[0].custValid() === false) {
			          return
			        }
			      }
				 
				var url = Vue.__ctx + "/form/formDefData/saveData?key=" + $.getParam("key") + "&sql=" + $.getParam("sql");
				var post = Vue.baseService.post(url, this.$children[0].$data.data);

				post.then(function(data) {
					if (data.isOk) {
						if(parent && parent.reloadGrid){
							parent.reloadGrid();
						}
						$.Dialog.confirm("提示信息", "添加成功，是否需要继续添加", function() {
							window.location = window.location;
						}, function() {
							$.Dialog.close(window);
						})
					} else {
						$.Dialog.error(data.msg);
					}

				}, function(e) {
					alert(e);
				});
			}
		},
		created : function() {
			var url = Vue.__ctx + "/form/formDefData/getData";
			var post = Vue.baseService.postForm(url, {
				key : $.getParam("key"),
				id : $.getParam("id"),
				sql : $.getParam("sql"),
			});
			var that = this;
			$.getResultData(post, function(data) {

				window.custFormComponentMixin = {};
				var html = data.html;
				if (window.passData) {// 前端html传过来
					html = window.passData.html;
				}

				Vue.formService.initCustFormFu(html, data);
				that.$data.loaded = true;
			});
		},
		watch : {

		}
	});
</script>
</html>